#!/usr/bin/env python
#-*- coding:utf-8 -*-

'''
配置mysql模型
author:cold night
email:wh_linux@126.com
'''
from model.get_db import get_db
from model.common import not_empty


__all__ = ['insert_option', 'get_option']
conn = get_db()
cursor = conn.cursor()


def insert_option(option_dict):
    not_empty(option_dict)
    try:
        for key, value in option_dict.items():
            sql = 'insert into options(`option`, `value`) VALUES(%s, %s) on duplicate key update value=%s'
            param = (key, value, value)
            cursor.execute(sql, param)
            conn.commit()
            
        return True
    except:
        return False
    


def get_option(key):
    not_empty(key)
    sql = 'select `value` from options where `option`=%s'
    param = key,
    cursor.execute(sql, param)
    r = cursor.fetchone()[0]
    return r
